package com.example.util.tree;

import java.util.ArrayList;
import java.util.List;

public class TreeNode<T>  {

    private T data;                    // 节点数据
    private List<TreeNode<T>> children; // 子节点列表

    public TreeNode(T data) {
        this.data = data;
        this.children = new ArrayList<>();
    }

    // getter和setter方法
    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public List<TreeNode<T>> getChildren() {
        return children;
    }

    public void setChildren(List<TreeNode<T>> children) {
        this.children = children;
    }

    // 添加子节点
    public void addChild(TreeNode<T> child) {
        this.children.add(child);
    }

    @Override
    public String toString() {
        return "TreeNode{data=" + data + ", children=" + children.size() + "}";
    }
}
